﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace LED_Utils
{
    public static class ReflectionHelper
    {
        public static object GetValue(object obj, string propName)
        {
            if (obj == null) throw new ArgumentNullException("obj");
            PropertyInfo info = GetPropertyInfo(obj, propName);
            return info.GetValue(obj, null);
        }

       
        public static void SetValue(object obj, string propName, object val)
        {
            if (obj == null) throw new ArgumentNullException("obj");
            PropertyInfo info = GetPropertyInfo(obj, propName);
            info.SetValue(obj, val, null);
        }

        private static PropertyInfo GetPropertyInfo(object obj, string propName)
        {
            Type type = obj.GetType();
            PropertyInfo info = type.GetProperty(propName);
            if (info == null)
                throw new InvalidOperationException("Property " + propName + " not found");
            return info;
        }


    }
}
